package logic

import (
	"context"
	"goods-srv/model/mysql"

	"goods-srv/goods"
	"goods-srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsListLogic) GoodsList(in *goods.GoodsListRequest) (*goods.GoodsListResponse, error) {
	// todo: add your logic here and delete this line
	var GoodsList []*goods.GoodsInfo
	p := mysql.Goods{}
	list, err := p.List(int(in.Page), int(in.Limit), in.GoodsTitle)
	if err != nil {
		return nil, err
	}
	for _, v := range list {
		GoodsList = append(GoodsList, &goods.GoodsInfo{
			GoodsTitle:  v.GoodsTitle,
			GoodsPrice:  v.GoodsPrice,
			GoodsStock:  v.GoodsStock,
			GoodsCover:  v.GoodsCover,
			GoodsStatus: v.GoodsStatus,
			GoodsType:   v.GoodsType,
		})
	}
	return &goods.GoodsListResponse{GoodsList: GoodsList}, nil
}
